<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>

<div id="comments" class="word-comments">
    <?php $this->comments()->to($comments); ?>
    <?php if ($comments->have()): ?>
    <h3 class="font-songti text-size-4 mb-4"><?php $this->commentsNum(_t('暂无留言'), _t('仅有一条留言'), _t('已有 %d 条留言')); ?></h3>
    
    <?php $comments->listComments(); ?>

    <?php $comments->pageNav('&laquo; 前一页', '后一页 &raquo;'); ?>
    
    <?php endif; ?>

    <?php if($this->allow('comment')): ?>
    <div id="<?php $this->respondId(); ?>" class="respond mt-8">
        <div class="cancel-comment-reply">
            <?php $comments->cancelReply(); ?>
        </div>
    
        <h3 id="response" class="font-songti text-size-4 mb-4"><?php _e('添加新留言'); ?></h3>
        <form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form" class="space-y-4">
            <?php if($this->user->hasLogin()): ?>
            <p class="font-fangSong text-size-4"><?php _e('登录身份: '); ?><a href="<?php $this->options->profileUrl(); ?>" class="text-blue-600"><?php $this->user->screenName(); ?></a>. <a href="<?php $this->options->logoutUrl(); ?>" title="Logout" class="text-red-600"><?php _e('退出'); ?> &raquo;</a></p>
            <?php else: ?>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                <div class="col-span-1">
                    <label for="author" class="block font-fangSong text-size-4 mb-1"><?php _e('称呼'); ?> <span class="text-red-500">*</span></label>
                    <input type="text" name="author" id="author" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="<?php $this->remember('author'); ?>" required />
                </div>
                <div class="col-span-1">
                    <label for="mail" class="block font-fangSong text-size-4 mb-1"><?php _e('邮箱'); ?><?php if ($this->options->commentsRequireMail): ?> <span class="text-red-500">*</span><?php endif; ?></label>
                    <input type="email" name="mail" id="mail" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?> />
                </div>
                <div class="col-span-1">
                    <label for="url" class="block font-fangSong text-size-4 mb-1"><?php _e('网站'); ?><?php if ($this->options->commentsRequireURL): ?> <span class="text-red-500">*</span><?php endif; ?></label>
                    <input type="url" name="url" id="url" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?> />
                </div>
            </div>
            <?php endif; ?>
            <div>
                <label for="textarea" class="block font-fangSong text-size-4 mb-1"><?php _e('内容'); ?> <span class="text-red-500">*</span></label>
                <textarea rows="8" name="text" id="textarea" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required><?php $this->remember('text'); ?></textarea>
            </div>
            <div>
                <button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors"><?php _e('提交留言'); ?></button>
            </div>
        </form>
    </div>
    <?php else: ?>
    <h3 class="font-songti text-size-4 mb-4"><?php _e('留言已关闭'); ?></h3>
    <?php endif; ?>
</div>